package cn.kgc.service;

import cn.kgc.common.CrowdFundingUtils;
import cn.kgc.mapper.HmoldMapper;

import cn.kgc.pojo.Hmold;
import cn.kgc.pojo.HmoldExample;

import cn.kgc.pojo.UserExample;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class MoldServiceImpl implements MoldService{

    @Resource
    HmoldMapper hmoldMapper;


    @Override
    public PageInfo<Hmold> queryForKeywordSearch(Integer pageNum, Integer pageSize, String keyword) {
        PageHelper.startPage(pageNum,pageSize);

        if (keyword==null) {
            List<Hmold> users = hmoldMapper.selectByExample(null);
            PageInfo<Hmold> pageInfo=new PageInfo<>(users);
            return pageInfo;
        }else{
            HmoldExample example=new HmoldExample();
            HmoldExample.Criteria criteria = example.createCriteria();
            //根据姓名查询
            criteria.andHousemoldLike("%"+keyword+"%");

            List<Hmold> users = hmoldMapper.selectByExample(example);
            PageInfo<Hmold> pageInfo=new PageInfo<>(users);
            return pageInfo;
        }
    }

    @Override
    public Hmold selectByIdUser(Integer id) {
        return hmoldMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<Hmold> getUserListByIdList(List<Integer> userIdList) {
        HmoldExample example=new HmoldExample();
        HmoldExample.Criteria criteria = example.createCriteria();
        criteria.andIdIn(userIdList);

        return hmoldMapper.selectByExample(example);
    }

    @Override
    public void batchRemove(List<Integer> userIdList) {
        HmoldExample example=new HmoldExample();
        HmoldExample.Criteria criteria = example.createCriteria();
        criteria.andIdIn(userIdList);
        hmoldMapper.deleteByExample(example);
    }

    @Override
    public void remove(Integer id) {
        hmoldMapper.deleteByPrimaryKey(id);
    }

    @Override
    public Hmold selectById(Integer id) {
        return    hmoldMapper.selectByPrimaryKey(id);
    }

    @Override
    public void updateUser(Hmold user) {

        hmoldMapper.updateByPrimaryKeySelective(user);
    }

    @Override
    public void saveUser(Hmold user) {

        hmoldMapper.insert(user);
    }
}
